using UnityEngine;
using System.Collections.Generic;
using System;
using JetBrains.Annotations;
using UBlockly.Scriptable;
using UBlockly.UI;
using UBlockly.Sys;
using UBlockly.Util;
using UBlockly.Compotent;
using UBlockly.Graphic;

namespace UBlockly
{
    /// <summary>
    /// tip挂载ui
    /// </summary>
    internal sealed class BlockTipUIPanel : MonoBehaviour
    {
        private Dictionary<string,IParamSetterPanel> setterMap = new Dictionary<string, IParamSetterPanel>();

        public void InitSetterPanel()
        {
            var defines = Enum.GetNames(typeof(SetterDefine));
            foreach (var df in defines)
            {
                SetterDefine type = (SetterDefine)Enum.Parse(typeof(SetterDefine), df);
                
                var panel = BlockGraphicSetter.GetPanel(type);
                if (panel != null)
                {
                    panel = GameObject.Instantiate(panel) as IParamSetterPanel;
                    panel.transform.SetParent(transform);
                    panel.gameObject.SetActive(false);
                    setterMap.Add(type.ToString(),panel);
                }
                else
                {
                    Debug.LogWarning($"type:{df} setter is null");
                }
            }
        }

        public IParamSetterPanel OpenSetterPanel(Type type)
        {
            IParamSetterPanel panel = null;
            var target = GraphicHelper.ToSetterDefine(type.Name);
            Debug.LogError("tttt:"+target.ToString());
            if (setterMap.TryGetValue(target.ToString(), out panel))
            {
                panel.Open();
                return panel;
            }

            return null;
        }
        
    }
}